package com.example.design.dahua.strategy.new4strategyandfactory;

/**
 * @author ebnew
 * 简单工厂
 * 将实例化具体策略的过程由客户端转移到context类中，简单工厂的应用
 */
public class CashContext {
     private AbstractCash cash;

     public  CashContext(String type){
         switch (type){
             case "正常收费":
                 cash=new CashNormal();
                 break;
             case "打8折":
                 cash=new CashRebate(0.8d);
                 break;
             case "满300返100":
                 cash=new CashReturn(300,100);
                 break;
             default:
                 throw new RuntimeException("");
         }
     }

     public double getResult(double money){
         return cash.acceptCash(money);
     }
}
